<?php
/**
 * Klasse zur Erstellung von Popup-Menues
 *
 * @author		Joachim Ruf
 * @copyright	Copyright (c) 2003-2010 Loresoft Software (http://www.loresoft.de)
 * @license		http://yapary.loresoft.de/lizenzbedingungen     New BSD License
 * @uses		jquery-1.4.2.min.js
 *
 * */


/*
 <!-- Strukturelle Aufbau eines Menueeintrags -->
 <ul class="popupMenuBorder">
 	<li>MenuTitle
     	<ul class="popupMenuBody">
     		<li>Entry1</li>
     		<li class="selected">Entry2</li>
     		<li class="popupMenuSubmenu" onmouseover="...">
     			Entry3
             	<ul class="popupMenuSubmenu" id="">
             		<li>SubEntry3.1</li>
             		<li>SubEntry3.2</li>
             		<li>...</li>
             	</ul>
     		</li>
     	</ul>
 	</li>
 </ul>
*/


Class Yapary_Menu_PopupMenu Implements Yapary_Menu_IPopupMenu
{
    /** @var $content string */
    private $content  = NULL;
    /** @var $name string */
    private $uniqueName    = NULL;
    /** @var $arrData array() */
    private $arrData = array();
    /** @var $id string	: Einmalige Id */
    private $id      = NULL;


    /**
     * @param Object $_oSql	: Datenbankklasse fuer Datenbankzugriff
     * */
    function __construct ($_uniqueName = '', $_content)
    {
        $this->uniqueName = $_uniqueName;
        $this->content = $_content;
    }


    /**
     * Fuegt einen neuen Datensatz hinzu
     * @param mixed $_content 	: einzufuegender Content
     * @return Yapary_Menu_PopupMenu
     * */
    public function addEntry ($_content)
    {
        return $this->arrData[] = new Yapary_Menu_PopupMenuEntry(count($this->arrData)+1, $_content);
    }


    /**
     * Fuegt einen neuen Datensatz hinzu
     * @param mixed $_content 	: einzufuegender Content
     * @return Yapary_Menu_PopupMenu
     * */
    public function addSubmenu ($_content)
    {
        return $this->arrData[] = new Yapary_Menu_PopupMenuSubmenu(count($this->arrData)+1, $_content);
    }


    /**
     * Loescht einen existierenden Datensatz
     * @return bool
     * */
    public function delete ($index)
    {
        if (!isset($this->arrData[$index])) {
            return false;
        }

        unset($this->arrData[$index]);
        return true;
    }


    /**
     * Liefert das gesammte Menu
     * @return string
     * */
    public function display ()
    {
        $result = '';

        if (count($this->arrData)) {
            while (list(,$object) = each($this->arrData)) {
                $result .= $object->display();
            }
        }

        if ($result != '') {
            $result = '<ul class="popupMenuBody" id="'.$this->uniqueName.'Body">
    						'.$result.'
    					</ul>';
        }

        // IE onmouseout Problem
        return '<ul class="popupMenuBorder">
        			<li>'.$this->content.'
						'.$result.'
					</li>
        		</ul>';
    }


}


?>